package com.training.web.controller.comtent;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.training.common.annotation.Log;
import com.training.common.core.controller.BaseController;
import com.training.common.core.domain.AjaxResult;
import com.training.common.enums.BusinessType;
import com.training.content.domain.CommonFileInfo;
import com.training.content.service.ICommonFileInfoService;
import com.training.common.utils.poi.ExcelUtil;
import com.training.common.core.page.TableDataInfo;

/**
 * 公共文件Controller
 * 
 * @author training
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/common/file")
public class CommonFileInfoController extends BaseController
{
    @Autowired
    private ICommonFileInfoService commonFileInfoService;

    /**
     * 查询公共文件列表
     */
    @PreAuthorize("@ss.hasPermi('common:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonFileInfo commonFileInfo)
    {
        startPage();
        List<CommonFileInfo> list = commonFileInfoService.selectCommonFileInfoList(commonFileInfo);
        return getDataTable(list);
    }

    /**
     * 导出公共文件列表
     */
    @PreAuthorize("@ss.hasPermi('common:file:export')")
    @Log(title = "公共文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CommonFileInfo commonFileInfo)
    {
        List<CommonFileInfo> list = commonFileInfoService.selectCommonFileInfoList(commonFileInfo);
        ExcelUtil<CommonFileInfo> util = new ExcelUtil<CommonFileInfo>(CommonFileInfo.class);
        return util.exportExcel(list, "公共文件数据");
    }

    /**
     * 获取公共文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('common:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return AjaxResult.success(commonFileInfoService.selectCommonFileInfoByFileId(fileId));
    }

    /**
     * 新增公共文件
     */
    @PreAuthorize("@ss.hasPermi('common:file:add')")
    @Log(title = "公共文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonFileInfo commonFileInfo)
    {
        return toAjax(commonFileInfoService.insertCommonFileInfo(commonFileInfo));
    }

    /**
     * 修改公共文件
     */
    @PreAuthorize("@ss.hasPermi('common:file:edit')")
    @Log(title = "公共文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonFileInfo commonFileInfo)
    {
        return toAjax(commonFileInfoService.updateCommonFileInfo(commonFileInfo));
    }

    /**
     * 删除公共文件
     */
    @PreAuthorize("@ss.hasPermi('common:file:remove')")
    @Log(title = "公共文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(commonFileInfoService.deleteCommonFileInfoByFileIds(fileIds));
    }
}
